package com.JFapp.controller;

import com.JFapp.domain.dto.ChangePerformanceStatusDto;
import com.JFapp.domain.entity.Performance;
import com.JFapp.domain.entity.ResponseResult;
import com.JFapp.domain.vo.PerformanceVo;
import com.JFapp.eumns.AppHttpCodeEnum;
import com.JFapp.exception.SystemException;
import com.JFapp.service.PerformanceService;
import com.JFapp.service.RoleService;
import com.JFapp.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/repair/performance")
@Api(tags = "绩效管理")
public class PerformanceController {

    @Autowired
    private PerformanceService performanceService;

    @ApiOperation("查询个人绩效")
    @GetMapping("/selectPerformanceByUid")
    public ResponseResult selectPerformanceByUid(Integer pageNum,Integer pageSize){
        return performanceService.selectPerformanceByUid(pageNum,pageSize);
    }

    @ApiOperation("查询绩效根据姓名")
    @GetMapping("/{userName}")
    public ResponseResult selectPerformanceByName(@PathVariable String userName,Integer pageNum,Integer pageSize){

        return performanceService.selectPerformanceByName(userName,pageNum,pageSize);
    }

    @GetMapping("/selectRanking")
    @ApiOperation("查询排名")
    public  ResponseResult selectRanking(@Param("start") Long start,@Param("end") Long end){
        return performanceService.selectRanking(start,end);
    }


    @ApiOperation("新增绩效申请单")
    @PostMapping("/changePerformance")
    public ResponseResult changePerformance(@RequestBody @Validated PerformanceVo performanceVo){
        return performanceService.changePerformance(performanceVo);
    }

    @ApiOperation("查询待审核绩效单")
    @GetMapping("/getAuditPerformanceByUserId")
    public ResponseResult getAuditPerformanceByUserId(Integer pageNum,Integer pageSize){
        return performanceService.getAuditPerformanceByUserId(pageNum,pageSize);
    }

    @ApiOperation("更改绩效申请单")
    @PostMapping("/updateChangePerformance")
    public ResponseResult updateChangePerformance(@RequestBody @Validated PerformanceVo performanceVo){
        return performanceService.updateChangePerformance(performanceVo);
    }

    @ApiOperation("取消待审核绩效单")
    @DeleteMapping("/{performanceId}")
    public ResponseResult deleteAuditPerformance(@PathVariable Long performanceId){
        return performanceService.deleteAuditPerformance(performanceId);
    }

    @ApiOperation("查询待审核绩效单")
    @GetMapping("/getAuditPerformance")
    @PreAuthorize("@ps.hasPermission('repair:performance:audit')")
    public ResponseResult getAuditPerformance(Integer pageNum,Integer pageSize){
        return performanceService.getAuditPerformance(pageNum,pageSize);
    }

    @ApiOperation("绩效审核")
    @PostMapping("/changePerformance/audit")
    @PreAuthorize("@ps.hasPermission('repair:preformance:audit')")
    public ResponseResult changePerformanceAudit(@RequestBody ChangePerformanceStatusDto changePerformanceStatusDto){
        return performanceService.changePerformanceAudit(changePerformanceStatusDto.getPerformance(),changePerformanceStatusDto.getAudit());
    }
}
